package com.salon.common.utils;

import com.salon.config.AesEncryptConfig;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class AesUtils {

    @Autowired
    private AesEncryptConfig aesEncryptConfig;

    /**
     * aes加密
     */
    public String aesHexEncrypt(String param) {
        if (StringUtils.isEmpty(param)) {
            return param;
        }
        try {
            param = AesEncryptUtils.aesHexEncrypt(param, aesEncryptConfig.getAesKey());
        } catch (Exception e) {
            log.error("===aesHexEncrypt is fail param===" + param + "===error===" + e);
        }
        return param;
    }

    /**
     * aes解密
     */
    public String aesHexDecrypt(String param) {
        if (StringUtils.isEmpty(param)) {
            return param;
        }
        try {
            param = AesEncryptUtils.aesHexDecrypt(param, aesEncryptConfig.getAesKey());
        } catch (Exception e) {
            log.error("===aesHexDecrypt is fail param===" + param + "===error===" + e);
        }
        return param;
    }

}
